<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>

    <script type="text/javascript" src="js/jquery-3.5.1.js"></script>

</head>
<body>
    <h3>学生信息管理系统</h3>
    <form id="form">
        <input type="text" name="username" placeholder="请输入用户名"> <br>
        <input type="password" name="password" placeholder="请输入密码"> <br>
        <input id="button1" type="button" value="登录">
        <input id="button2" type="button" value="注册">
    </form>

</body>

<script>
    // 点击登录按钮，向UserServlet发送请求
    $("#button1").click(function(){
        $.ajax({
            type:"get",
            url:"/Code/userServlet",
            data:$("#form").serialize(),
            async:true,
            success:function(data){
                var d = eval("(" + data + ")");
                if(d.isExist){
                    window.location.href="view.html";
                }else{
                    alert("登录失败！！！");
                    window.location.href="index.html";
                }
            },
        })
    })

    // 点击注册按钮，向LoginServlet发送请求
    $("#button2").click(function(){
        $.ajax({
            type:"get",
            url:"/Code/loginServlet",
            data:$("#form").serialize(),
            async:true,
            success:function(data){
                var d = eval("(" + data + ")");
                if(d.isExist){
                    alert("注册成功！！！");
                }else{
                    alert("注册失败！！！");
                }
                window.location.href="index.html";
            }
        })
    })
</script>
</html>